129

129

DOI: 10.1201/9781003214335-10

Real-​Time Currency

Conversion

An Introduction to Simple

Web Scraping Techniques

There are two types of information one is accustomed to using these days—​informa­

tion at work that is required to do one’s job and information at home to complete a

personal chore. The former is mostly on spreadsheets—​sales figures, targets, budgets,

etc. The latter is mostly on the web—​for example, where is the nearest gas station,

when does my favorite Indian restaurant close, and so on.

What if I need both types at once? What if I am trying to compile a list of hotels within

a five-​mile radius of 40 different office locations in the United States for my company?

In fact, most jobs that have even a small amount of research content involve pulling

data from the web and compiling them for further analysis. A financial consultant may

be looking at the exchange rates and compiling them every single day. A fund manager

may be interested in a daily update of stock prices to analyze trends, etc.

The art of grabbing information from the web without manually inputting a web

address or an input into a web interface is called “Scraping”. This chapter will show

you some techniques on how to do this and effectively merge this information into

a spreadsheet that possibly has other data items, thus enriching the total information

available in the document. The example used here is to demonstrate an automatic

currency conversion. We use Internet Explorer for this example, as it is easily in­

tegrated into Excel. Other browsers can be used as well for this exercise, but they

require a different code treatment not discussed here. I already hear some rumblings

that this is not your preferred browser. The point is, once developed, this is pretty

much invisible, so you do not have to physically interact with the browser at all. If

you do use another browser, the code might look slightly different and may require

other pieces of software to be installed. For example, using Google Chrome and Edge

browsers require the installation of Selenium. Please see the resources page online for

a code example using the Edge Browser.

9.1  ALGORITHM

The algorithm for the program works in three simple steps:

• Step 1—​launch the web page

• Step 2—​enter the currency pairs required from an input spreadsheet

• Step 3—​get the exchange rate displayed and copy it into an output spreadsheet

9